from base.base_filters import BaseFilter


class TagFilter(BaseFilter):
    @staticmethod
    def filter_name(query, value):
        return query.filter(name__contains=value)


class CategoryFilter(BaseFilter):
    @staticmethod
    def filter_name(query, value):
        return query.filter(name__contains=value)


class ArticleFilter(BaseFilter):
    @staticmethod
    def filter_title(query, value):
        return query.filter(title__contains=value)

    @staticmethod
    def filter_category(query, value):
        return query.filter(category_id=value)

    @staticmethod
    def filter_tags(query, value: list[str]):
        return query.filter(tags__id__in=value)

    @staticmethod
    def filter_content(query, value):
        return query.filter(content__contains=value)

    @staticmethod
    def filter_status(query, value):
        return query.filter(status=value)

    @staticmethod
    def filter_q(query, value):
        return query.filter(title__contains=value) | query.filter(
            content__contains=value
        )

    @staticmethod
    def filter_category_short_name(query, value):
        return query.filter(category__short_name=value)
